﻿using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Navigation;
using GalaSoft.MvvmLight;
using Mal.Balades.Admin.ViewModels;

namespace Mal.Balades.Admin.Views.VisitViews.Dashboard
{
    public partial class Main : Page
    {
        public Main()
        {
            InitializeComponent();    
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (this.DataContext is PageViewModelBase)
            {
                ((PageViewModelBase)this.DataContext).NavigationContext = this.NavigationContext;
                ((PageViewModelBase)this.DataContext).OnNavigate();
            }
        }

        protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            if (this.DataContext is ViewModelBase)
            {
                ((PageViewModelBase)this.DataContext).Cleanup();
            }
        }

        private void TextBox_KeyUp(object sender, KeyEventArgs e)
        {
            var bindingExpression = ((TextBox)sender).GetBindingExpression(TextBox.TextProperty);

            if (bindingExpression != null)
            {
                bindingExpression.UpdateSource();
            }
        }
    }
}
